<?php
/*
  开发作者：南阳迈特网络科技有限公司
  QQ:794929988
*/

namespace app\admin\model\drama;

use think\Model;


class Membersnumber extends Model
{

    

    

    // 表名
    protected $name = 'drama_membersnumber';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'performer_text',
        'performer_avatar',
    ];
    
    public function setTimeAttr($value)
    {
        return strtotime($value);
    }
    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getTypeList()
    {
        // return ['d' => '天', 'm' => '月', 'q' => '季', 'y' => '年'];
        return ['w' => '本周', 'm' => '本月'];
    }
    public function getPerformerList()
    {
        return VideoPerformer::where(['type'=>'performer'])->group('name')->order(['weigh'=>'asc'])->select();
    }
    
    public function getStatusList()
    {
        return ['0' => '隐藏', '1' => '显示'];
    }

    public function getPerformerTextAttr($value, $data)
    {
        return VideoPerformer::where(['id'=>$data['performer_id']])->value('name');
    }
    
    public function getPerformerAvatarAttr($value, $data)
    {
        return VideoPerformer::where(['id'=>$data['performer_id']])->value('avatar');
    }
    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
